home *** CD-ROM | disk | FTP | other *** search
- Path: sun001.spd.dsccc.com!spd!jmccarty
- From: jmccarty@spd.dsccc.com (Mike McCarty)
- Newsgroups: comp.lang.c
- Subject: Re: sscanf bug??????
- Date: 14 Feb 1996 19:38:34 GMT
- Organization: DSC Communications Corporation, Plano, Texas USA
- Message-ID: <4ftdnq$b0c@sun001.spd.dsccc.com>
- References: <4fimvo$82s@fnord.dfw.net> <4frr9j$ie8@fnord.dfw.net>
- NNTP-Posting-Host: aplo139.spd.dsccc.com
-
- In article <4frr9j$ie8@fnord.dfw.net>,
- Jerry Jackson <jtmcap@dfw.dfw.net> wrote:
- )Jerry Jackson (jtmcap@dfw.dfw.net) wrote:
- ): the following is a program compiled using microway ndp c/c++ compiler.
- ):
- ): #include <stdio.h>
- ): #include <string.h>
- ):
- ): main()
- ): {
- ): char str_1[] = "013196";
- ): char str_2[] = "13196";
- ): long res_1, res_2;
- ):
- ): sscanf(str_1,"%d",&res_1);
- ): sscanf(str_2,"%d",&res_2);
- ):
- ): printf("\nres_1 = %d",res_1);
- ): printf("\nres_2 = %d",res_2);
- ): }
- ):
- ): the output looks like this:
- ):
- ): res_1 = 89
- ): res_2 = 13196
- ):
- ):
- ): microway says that the leading zero causes sscanf to do an octal
- ): conversion on the integer. i have not found any documentation to verify
- ): this. also other compilers that i use return the value 13196 for both
- ): calls to sscanf.
- ):
- ): bug or undocumented feature?
- ):
-
- Per the ANSI standard, "%d" specifies a decimal integer, whereas "%i"
- specifies integer, the string may begin with 0 (indicating octal
- translation), or either of "0x" or "0X" to specify hexadecimal
- translation. So if it is a "feature", it is not ANSI.
-
- In any case, 013196 (octal) is 718 decimal. 718 decimal mod 256 is 206.
- I don't see anything reasonable it could be the mod of that would
- result in 89. So even if it is an "undocumented feature" or non-ANSI
- extension, I don't think it is working properly.
-
- Mike
- ----
- char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
-
- I don't speak for DSC. <- They make me say that.
-